package com.example.demo6.controller;

import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demo6.common.Result;
import com.example.demo6.entity.Book;
import com.example.demo6.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/book")

public class BuyBookcontroller {
    @Autowired
    private BookService bookService;

    @PostMapping("/buy")
    private Result<Book> Buy(@RequestBody Book book){
        String name=book.getName();

        LambdaQueryWrapper<Book> queryWrapper=new LambdaQueryWrapper<>();

        queryWrapper.eq(Book::getName,book.getName());

        Book bookTemp =bookService.getOne(queryWrapper);

        if(bookTemp!=null){
            return Result.success(bookTemp,"成功");
        }
        return Result.error("失败");
    };


}
